## 指令
## 1. cmakelist同级目录下执行：cmake -S . -B build
## 2. cd build && cmake --build . --config Release
## 3. cmake --install . --config Release
## rsync -avrHP a56sw01@192.168.120.98:/home/a28sw02/ssd_data2/  ./

cmake_minimum_required(VERSION 3.14)

# 工程名
set(PROJECT_NAME "auto_find")
project(${PROJECT_NAME} LANGUAGES CXX)

set(PLUGIN_NAME "auto_find")

# 资源文件
list(APPEND PLUGIN_SOURCES
        Handle.cpp
        CMD.cpp
        Cmdd.cpp
        Test.cpp
        CJSON/cJSON.cpp
        CJSON/cJSON_Utils.cpp
        ThreadPool/ThreadPool.cpp
        Utils/Utils.cpp
        log/log.cpp
)

add_executable(${PROJECT_NAME}
        AutoFind.cpp
        AutoFind.h
        version.h
        ${PLUGIN_SOURCES}
)

IF( WIN32 )
    SET ( CMAKE_SHARED_LINKER_FLAGS /MANIFEST:NO )
    #加这个才能识别到win10
    add_custom_command(
            TARGET ${PROJECT_NAME}
            POST_BUILD
            COMMAND "mt.exe" -manifest \"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.exe.manifest\" -outputresource:"${CMAKE_CURRENT_SOURCE_DIR}/build/Release/${PROJECT_NAME}.exe"\;\#1
            COMMENT "Adding manifest...${CMAKE_CURRENT_SOURCE_DIR}"
    )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4819 -wd4996 /std:c++20 -D__STDC_CONSTANT_MACROS -DWIN32_LEAN_AND_MEAN")

ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    # 设置需要链接的线程库
    set(CMAKE_THREAD_LIBS_INIT "-lpthread")
    # 查找并使用线程库
    find_package(Threads REQUIRED)
    # 将线程库添加到目标链接库中
    target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_THREAD_LIBS_INIT})

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")
ENDIF( WIN32 )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLOG_USE_COLOR ")

SET(CMAKE_BUILD_TYPE Release)

#版本自增
add_custom_target(
        update_version
        COMMAND ${CMAKE_COMMAND} -D GIT_VERSION=${GIT_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/update.cmake
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_dependencies(${PLUGIN_NAME} update_version)

set_target_properties(${PLUGIN_NAME} PROPERTIES
        CXX_VISIBILITY_PRESET hidden)

# 宏定义
target_compile_definitions(${PLUGIN_NAME} PRIVATE CPP_TOOLS_IMPL)

include_directories(
        "${CMAKE_CURRENT_SOURCE_DIR}/CJSON"
        "${CMAKE_CURRENT_SOURCE_DIR}/Utils"
        "${CMAKE_CURRENT_SOURCE_DIR}/log"
        "${CMAKE_CURRENT_SOURCE_DIR}/ThreadPool"
)




